﻿using System;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace HobSoft.SoccerBet2014.Domain.Models
{
    using Core;
    using KeyHelper;
    [Serializable]
    [DataContract]
    public class Game : IModel
    {
        public Game()
        {
            _rawJson = new StringBuilder();
            State = GameState.PreGame;
        }

        [PrimaryKey]
        [Required]
        [DataMember(IsRequired = true)]
        public string Key
        {
            get { return KeyGenerateHelper.Create<Game>(this); }
            set { ; }
        }

        private byte _bmId;
        [Key]
        [DataMember(IsRequired = true)]
        public byte BmID
        {
            get { return _bmId; }
            set { _bmId = value; }
        }

        private string _gameID;
        [Key]
        [MaxLength(50)]
        [MinLength(1)]
        [DataMember(IsRequired = true)]
        public string GameID
        {
            get { return _gameID; }
            set { _gameID = value; }
        }

        private string _gameCode;
        [MaxLength(50)]
        [MinLength(1)]
        [DataMember(IsRequired = true)]
        public string GameCode
        {
            get { return _gameCode; }
            set { _gameCode = value; }
        }

        private string _homeTeam;
        [Required]
        [MaxLength(50)]
        [MinLength(1)]
        [DataMember(IsRequired = true)]
        public string HomeTeam
        {
            get { return _homeTeam; }
            set { _homeTeam = value; }
        }

        private string _awayTeam;
        [Required]
        [MaxLength(50)]
        [MinLength(1)]
        [DataMember(IsRequired = true)]
        public string AwayTeam
        {
            get { return _awayTeam; }
            set { _awayTeam = value; }
        }

        private string _tournamentId;
        [Required]
        [DataMember(IsRequired = true)]
        public string TournamentID
        {
            get { return _tournamentId; }
            set { _tournamentId = value; }
        }

        private string _tournament;
        [MaxLength(100)]
        [MinLength(1)]
        [Required]
        [DataMember(IsRequired = true)]
        public string Tournament
        {
            get { return _tournament; }
            set { _tournament = value; }
        }

        private byte _homeScore;
        [DataMember]
        public byte HomeScore
        {
            get { return _homeScore; }
            set { _homeScore = value; }
        }

        private byte _awayScore;
         [DataMember]
        public byte AwayScore
        {
            get { return _awayScore; }
            set { _awayScore = value; }
        }

        private byte _homeRed;
         [DataMember]
        public byte HomeRed
        {
            get { return _homeRed; }
            set { _homeRed = value; }
        }

        private byte _awayRed;
         [DataMember]
        public byte AwayRed
        {
            get { return _awayRed; }
            set { _awayRed = value; }
        }

        private DateTime? _startTime;
         [DataMember]
        public DateTime? StartTime
        {
            get { return _startTime; }
            set { _startTime = value; }
        }

        private string _playTime;
         [DataMember]
        public string PlayeTime
        {
            get { return _playTime; }
            set { _playTime = value; }
        }

        private byte _playMinutes;
         [DataMember]
        public byte PlayMinutes
        {
            get { return _playMinutes; }
            set { _playMinutes = value; }
        }

        private byte _injuryMinutes;
         [DataMember]
        public byte InjuryMinutes
        {
            get { return _injuryMinutes; }
            set { _injuryMinutes = value; }
        }

        private byte _pried;
         [DataMember]
        public byte Pried
        {
            get { return _pried; }
            set { _pried = value; }
        }

        private string _lastUpdateHost;
         [DataMember]
        public string LastUpdateHost
        {
            get { return _lastUpdateHost; }
            set { _lastUpdateHost = value; }
        }

        private GameState _state;
         [DataMember]
        public GameState State
        {
            get { return _state; }
            set { _state = value; }
        }

        private DateTime _lastUpdateTime;
         [DataMember]
        public DateTime LastUpdateTime
        {
            get { return _lastUpdateTime; }
            set { _lastUpdateTime = value; }
        }

         [DataMember]
        public string RawJson
        {
            get { return _rawJson.ToString(); }
            set { _rawJson = new StringBuilder(value); }
        }


        private StringBuilder _rawJson;
        public void AppendRawJson(string json)
        {
            _rawJson.AppendLine(json);
        }

        public enum GameState : byte
        {
            PreGame = 0,
            InProgress = 1,
            Finish = 9,
        }
    }
}
